package org.example.controller;

import org.example.service.MqttPublisher;
import org.example.service.MqttSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MqttController {
    @Autowired
    private MqttPublisher mqttPublisher;
    @Autowired
    private MqttSubscriber mqttSubscriber;
    @GetMapping("/publish")
    public String publishMessage(@RequestParam String topic, @RequestParam String message) throws Exception {
        mqttPublisher.publish(topic, message);
        return "Message published";
    }

    @GetMapping("/subscribe")
    public String subscribeTopic(@RequestParam String topic) throws Exception {
        mqttSubscriber.subscribe(topic);
        return "Subscribed to topic";
    }
}
